package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-06-05
 * Time: 21:06
 */
//runnable实现1+2+3+...+100
public class Demo40 {

    private static int total = 0;

    public static void main(String[] args) throws InterruptedException {
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 1; i <= 100; i++) {
                    sum += i;
                }
                total = sum;
            }
        };

        Thread thread = new Thread(runnable);

        thread.start();
        thread.join();

        System.out.println("total = " + total);
    }
}
